package org.provider;

import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.bootstrap.builders.ServiceBuilder;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.example.service.DemoService;
import org.provider.service.DemoServiceImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 *
 */
@EnableDubbo
@SpringBootApplication
public class ProviderApp1 {
    public static void main( String[] args ) {
        SpringApplication.run(ProviderApp1.class, args);
//        testMain();

//        testMain01();
    }

    public static void testMain01() {
        DubboBootstrap.getInstance()
                .application("demo-provider")
                .registry(new RegistryConfig("nacos://192.168.70.36:8848"))
                .protocol(new ProtocolConfig("dubbo", 50052))
                .service(
                        ServiceBuilder
                                .newBuilder()
                                .interfaceClass(DemoService.class)
                                .ref(new DemoServiceImpl())
                                .build()
                )
                .start()
                .await();

    }

    public static void testMain() {
        DubboBootstrap.getInstance()
                .protocol(new ProtocolConfig("dubbo", 50051))
                .service(
                        ServiceBuilder
                                .newBuilder()
                                .interfaceClass(DemoService.class)
                                .ref(new DemoServiceImpl())
//                                .filter("org.example.filter.MyFilter")
                                .build()
                )
                .start()
                .await();
    }

}
